package 二叉树.遍历;

import 二叉树.TreeNode;

import java.util.Stack;


public class LDR {

    public static void traversal(TreeNode root) {
        if (root != null) {
            traversal(root.left);
            System.out.print(root.val + " ");
            traversal(root.right);
        }
    }

    public static void midTraversal(TreeNode root) {
        Stack<TreeNode> stack = new Stack<>();
        while (root != null || !stack.isEmpty()) {
            while (root != null) {
                stack.push(root);
                root = root.left;
            }
            if (!stack.isEmpty()) {
                System.out.print(stack.peek().val + " ");
                root = stack.pop();
                root = root.right;
            }
        }
    }
}
